package com.itoffer.web;

import com.itoffer.service.ApplicantService;
import com.itoffer.service.impl.ApplicantServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/selectByEmailServlet")
public class SelectByEmailServlet extends HttpServlet {
    private ApplicantService applicantService = new ApplicantServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取来自注册页面的参数
        String applicant_email = req.getParameter("applicant_email");

        //调用业务层注册方法注册
        boolean flag = applicantService.selectByEmail(applicant_email);

        if(flag){
            //用户存在
            resp.setContentType("text/json;charset=utf-8");
            resp.getWriter().write("exist");
        }else{
            //用户不存在
            resp.setContentType("text/json;charset=utf-8");
            resp.getWriter().write("noExist");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
